﻿using BW.WMS.CodeEnum;
using BW.WMS.RBAC;
using BW.WMS.XKY.DTO.Input;
using BW.WMS.XKY.DTO.Output;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace BW.WMS.XKY
{
    public class RoleAppService : ApplicationService, IRoleAppService
    {
        public readonly IRepository<RoleModel, Guid> _roleRepository;
        public RoleAppService(IRepository<RoleModel, Guid> roleRepository)
        {
            _roleRepository = roleRepository;
        }
        public async Task<ApiResult<int>> CreateAsync(RoleInput input)
        {
            var role=ObjectMapper.Map<RoleInput, RoleModel>(input);
            await _roleRepository.InsertAsync(role);
            return new ApiResult<int>() 
            {
                Code = ApiEnum.Success,
                Data = 1,
                Message = "添加成功"
            };
        }

        public async Task<ApiResult<int>> DeleteAsync(Guid id)
        {
            var role=await _roleRepository.GetAsync(id);
            await _roleRepository.DeleteAsync(role);
            return new ApiResult<int>() 
            {
                Code = ApiEnum.Success,
                Data = 1,
                Message = "删除成功"
            };
        }

        public async Task<ApiResult<List<RoleOutput>>> GetListAsync()
        {
            var roles =await _roleRepository.GetListAsync();
            return new ApiResult<List<RoleOutput>>()
            {
                Code = ApiEnum.Success,
                Data = ObjectMapper.Map<List<RoleModel>,List<RoleOutput>>(roles),
                Message = "查询成功"
            };
        }
    }
}
